package com.glela.test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.xml.soap.Detail;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.cxf.common.logging.Log4jLogger;
import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;
import org.apache.poi.hssf.record.ObjRecord;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Log4jConfigurer;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.base.BaseTest;
import com.glela.api.pay.yeepay.component.YeePay;
import com.glela.api.pay.yeepay.model.YeePayBaseRequest;
import com.glela.api.pay.yeepay.model.YeePayQueryDivideModel;
import com.glela.common.constant.CommonConstants;
import com.glela.common.constant.GoodsSelfTypeEnum;
import com.glela.common.constant.GoodsTypeEnum;
import com.glela.common.constant.KeepAccountsTypeConstants;
import com.glela.common.constant.PayTypeEnum;
import com.glela.common.constant.StoreTypeEnum;
import com.glela.common.constant.freightSettlementLimitEnum;
import com.glela.common.exception.PlatformException;
import com.glela.common.util.DateUtils;
import com.glela.common.util.HttpUtil;
import com.glela.common.util.JsonUtil;
import com.glela.common.util.ListUtils;
import com.glela.common.util.NumberUtil;
import com.glela.common.util.OrderUtil;
import com.glela.common.util.SmsContents;
import com.glela.common.util.SmsContentsError;
import com.glela.company.mapper.XzNotifyLogMapper;
import com.glela.company.model.XzNotifyLog;
import com.glela.company.model.XzOmsLog;
import com.glela.controller.OrderPayController;
import com.glela.order.mapper.AfterSalesMapper;
import com.glela.order.mapper.CommisionMapper;
import com.glela.order.mapper.OrderDetailMapper;
import com.glela.order.mapper.OrderInfoMapper;
import com.glela.order.mapper.OrderObjectMapper;
import com.glela.order.mapper.OrderPayMapper;
import com.glela.order.mapper.OrderSettlementMapper;
import com.glela.order.model.AfterSales;
import com.glela.order.model.Commision;
import com.glela.order.model.OrderDetail;
import com.glela.order.model.OrderInfo;
import com.glela.order.model.OrderObject;
import com.glela.order.model.OrderPay;
import com.glela.order.model.OrderSettlement;
import com.glela.order.model.request.RequestAfterSalesModel;
import com.glela.order.model.response.OrderObjectVo;
import com.glela.order.service.AfterSalesService;
import com.glela.order.service.OrderObjectService;
import com.glela.order.service.OrderPayService;
import com.glela.order.service.OrderService;
import com.glela.order.service.impl.AbstractOrderServiceImpl;
import com.glela.order.vo.OrderSettlementVo;
import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.mapper.OperationLogMapper;
import com.glela.platform.mapper.UserBankMapper;
import com.glela.platform.mapper.UserMapper;
import com.glela.platform.model.CUserPointTransaction;
import com.glela.platform.model.DumpConditions;
import com.glela.platform.model.OperationLog;
import com.glela.platform.model.PushMessage;
import com.glela.platform.model.User;
import com.glela.platform.model.UserBank;
import com.glela.platform.model.UserJournal;
import com.glela.platform.model.UserPointJournal;
import com.glela.platform.model.response.ResponseBaseModel;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.service.BaseRestrictionsService;
import com.glela.platform.service.PushMessageService;
import com.glela.platform.util.ParameterUtils;
import com.glela.talent.util.MyDateUtil;

public class dataCheck extends BaseTest {
//	private static Logger logger = LoggerFactory.getLogger(dataCheck.class);
	private static org.apache.log4j.Logger logger=LogManager.getLoggerRepository().getLogger("dataCheck");
	@Autowired
	private XzNotifyLogMapper xzNotifyLogMapper;
	@Autowired
	private OrderPayMapper orderPayMapper;
	@Autowired
	private OrderObjectMapper orderObjectMapper;
	@Autowired
	private AfterSalesService afterSalesService;
	@Autowired
	private OrderSettlementMapper orderSettlementMapper;
	@Autowired
	private CommisionMapper commisionMapper;
	@Autowired
	private AfterSalesService AfterSalesService;
	@Autowired
	private AfterSalesMapper afterSalesMapper;
	@Autowired
	private Map<String, OrderService>	orderServiceMap;
	@Resource(name="orderService2")
	private OrderService	orderService2;
	@Autowired
	protected YeePay yeePay;
	@Autowired
	protected OrderInfoMapper orderInfoMapper;
	@Autowired
	protected OrderDetailMapper orderDetailMapper;
	@Autowired
	protected UserMapper userMapper;
	@Autowired
	private OperationLogMapper operationLogMapper;
	@Autowired
	private BaseRestrictionsService  baseRestrictionsService;
	@Autowired
	private OrderObjectService  orderObjectService;
	@Autowired
	private PushMessageService pushMessageService;
	@Autowired
	private OrderPayService orderPayService;
	@Autowired
	private UserBankMapper userBankMapper;
	private MyDateUtil util = MyDateUtil.INSTANCE;
	private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");	
	// 主干
	@Test
	public void phoneMSG(){
		String orderSn="P150900848443365415";
		try {
			OrderObjectVo orderObjectVo = orderObjectService.getOrderObjectEntityByOrderSnTwo(orderSn);
			if (orderObjectVo.getPayType().intValue() == 0) {
				orderObjectVo.setPayType(PayTypeEnum.T23.getCode());
			}
			String t_id = null;
			List<OrderPay> selectSuccess = orderPayService.selectSuccess(orderObjectVo.getOrderSn());
			if (CollectionUtils.isEmpty(selectSuccess) && !StringUtils.equals(orderObjectVo.getOrderSn(), orderObjectVo.getPayId())) {
				return;
			} else if (selectSuccess.size() > 1) {
				return;
			} else if (selectSuccess.size() == 1) {
			} else {
				t_id = orderObjectVo.getOrderSn();
			}
			orderService2.updateOrderForXZOMS(orderObjectVo.getOrderSn(), "PAYtest", orderObjectVo.getPayType(), "PAY150900848806150718");
			orderObjectVo = null;
			selectSuccess = null;
			t_id = null;
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	public void main() {
		int status[]={2,3,4,6,7};//付款成功的状态
		List<OrderObject> list=
		orderObjectMapper.selectOrderObjectByStatusAndCreatTime(status,"2017-10-01 00:00:00","2017-10-21 23:59:59");
		for(OrderObject ObjOrder:list){
			try {
				//1.验证订单的支付状态
				List<OrderPay>  Paylist=orderPayMapper.selectPaySuccessByOBJOrderSn(ObjOrder.getOrderSn());
				if(Paylist!=null&&Paylist.size()>1){
					logger.error("APP记录 订单重复支付:"+ObjOrder.getOrderSn());
					continue;
				}
				if(Paylist==null||Paylist.size()==0){
					logger.error("APP记录 未找到支付记录:"+ObjOrder.getOrderSn());
					continue;
				}
				if(ObjOrder.getTotalFee()!=null&&ObjOrder.getTotalFee()>0){
					Map<Object, Object> requestMap=new HashMap<Object, Object>();
					requestMap.put("requestid",Paylist.get(0).getPaySn());
					String resultJSON=yeePay.yeePayQueryOrder(requestMap);
					JSONObject JO=JSONObject.parseObject(resultJSON);
					if("1".equals(JO.getString("code"))){
						if(!"SUCCESS".equals(JO.getString("status"))){
							logger.error("APP记录 订单未支付成功:"+ObjOrder.getOrderSn());
							continue;
						}
						if(Double.parseDouble(JO.getString("amount").toString())!=(ObjOrder.getTotalFee().intValue()/100.0)){
							logger.error("APP记录 订单实付金额和易宝查询不一致:"+ObjOrder.getOrderSn());
							continue;
						}
					}else{
						logger.error("APP记录 查找支付记录失败:"+ObjOrder.getOrderSn());
						continue;
					}
				}
			//2. 验证订单支付金额(只验证订单 子单明细单暂时不验证)
			 List<OrderInfo> OrderInfoList= orderInfoMapper.selectOrderInfoByOrderObjectIdC(ObjOrder.getId());
			 List<OrderDetail> OrderDetailList= orderDetailMapper.selectOrderDetilByOrderObjectId(ObjOrder.getId());
			 if(ObjOrder.getTotalPrice()-ObjOrder.getBalancePaid()-ObjOrder.getCashCoin()-
					 ObjOrder.getPromotionDiscount()+ObjOrder.getFreight()!=ObjOrder.getTotalFee()){
				 logger.error("父订单计算金额异常:"+ObjOrder.getOrderSn());
				 continue;
			 }
			 List<OrderSettlementVo> listSettle=
						orderSettlementMapper.selectByOrderSnForSettlementDetail(ObjOrder.getOrderSn());
					boolean OrderSettlementFlag=false;
					int orderFee=0;
					for(OrderSettlementVo Vo:listSettle){
						if(Vo.getTotalFee()>0&&
					 StringUtils.isBlank(Vo.getManagerAccount())&&StringUtils.isBlank(Vo.getCompanyAccount())){
							logger.info("结算单分账失败:"+Vo.getOrderSn());
							OrderSettlementFlag=true;
							break;
						}
						if(Vo.getTotalFee().intValue()>0){
							orderFee+=Vo.getTotalFee().intValue();
						}
					}
					if(OrderSettlementFlag){
						continue;
					}
					if(orderFee!=ObjOrder.getTotalFee().intValue()){
						logger.info("订单分账信息和订单实付信息不一致:"+ObjOrder.getOrderSn());
					}
					YeePayQueryDivideModel model=new YeePayQueryDivideModel();
					model.setOrderrequestid(Paylist.get(0).getPaySn());
					String result=yeePay.yeePayQueryDivide(model);
					JSONObject JSONresult=JSONObject.parseObject(result);
	 				if("1".equals(JSONresult.getString("code"))){//查询分账信息成功
	 					Map<String, Double> divide=
	 							yeePay.parsingYeePayDivide(JSONresult.getString("divideinfo"));
	 					String code=orderService2.compareDivide(listSettle,divide);
					    if("2".equals(code)){
					    	logger.info("查询订单分账信息失败:"+ObjOrder.getOrderSn());
					    }
	 				}else{
						logger.info("订单分账信息有误:"+ObjOrder.getOrderSn());
						continue;
					}
			} catch (Exception e) {
				logger.error("APP记录 订单出错:"+ObjOrder.getOrderSn()+":"+e.getMessage());
			}
		}
	}
	
	public void  yanzhengfenzhang(){

		org.apache.log4j.Logger logger=LogManager.getLoggerRepository().getLogger("dataCheck");
		//查询分账的时间段(昨天一整天)
//		List<OrderObject> list=orderObjectMapper.selectOrderByPayTime(util.getOldDays(1),util.getYesterday(new Date())); 
		List<OrderObject> list=orderObjectMapper.selectOrderByPayTime("2017-09-21 00:00:00","2017-09-30 23:59:59"); 
		int i=list.size(),j=0;
		//遍历订单查询分账信息
		for(OrderObject obj:list){
			j++;
			logger.info("-------list-"+i+"---------orderSN:"+obj.getOrderSn()+" begin"+" index:"+j);
			try {
				List<OrderPay>  Paylist=orderPayMapper.selectPaySuccessByOBJOrderSn(obj.getOrderSn());
				if(!ListUtils.isNotEmpty(Paylist)){
					logger.info("订单支付信息为空:"+obj.getOrderSn());
					continue;
				}
				if(ListUtils.isNotEmpty(Paylist)&&Paylist.size()>1){
					logger.info("订单重复支付:"+obj.getOrderSn());
					continue;
				}
				List<OrderSettlementVo> listSettle=
					orderSettlementMapper.selectByOrderSnForSettlementDetail(obj.getOrderSn());
				boolean OrderSettlementFlag=false;
				int orderFee=0;
				for(OrderSettlementVo Vo:listSettle){
					if(Vo.getTotalFee()>0&&
				 StringUtils.isBlank(Vo.getManagerAccount())&&StringUtils.isBlank(Vo.getCompanyAccount())){
						logger.info("结算单分账失败:"+Vo.getOrderSn());
						OrderSettlementFlag=true;
						continue;
					}
					if(Vo.getTotalFee().intValue()>0){
						orderFee+=Vo.getTotalFee().intValue();
					}
				}
				if(OrderSettlementFlag){
					continue;
				}
				if(orderFee!=obj.getTotalFee().intValue()){
					logger.info("订单分账信息和订单实付信息不一致:"+obj.getOrderSn());
				}
				YeePayQueryDivideModel model=new YeePayQueryDivideModel();
				model.setOrderrequestid(Paylist.get(0).getPaySn());
				String result=yeePay.yeePayQueryDivide(model);
				JSONObject JSONresult=JSONObject.parseObject(result);
 				if("1".equals(JSONresult.getString("code"))){//查询分账信息成功
 					Map<String, Double> divide=
 							yeePay.parsingYeePayDivide(JSONresult.getString("divideinfo"));
 					String code=orderService2.compareDivide(listSettle,divide);
				    if("2".equals(code)){
				    	logger.info("查询订单分账信息失败:"+obj.getOrderSn());
				    }
 				}else{
					logger.info("订单分账信息有误:"+obj.getOrderSn());
					continue;
				}
 				logger.info("------list-"+i+"-----------orderSN:"+obj.getOrderSn()+" end"+" index:"+j);
			} catch (Exception e) {
				logger.info(e.getMessage());
			}
		}
	}
	
public ResponseEntity yy(AfterSales afterSaless){
	YeePayBaseRequest yeePayBaseRequest=new YeePayBaseRequest();
//	HttpServletRequest request=new HttpServletRequest();
	yeePayBaseRequest.setAfterSn("A150840721250808750");
	try {
		if (ParameterUtils.validParams(yeePayBaseRequest.getAfterSn())) {
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
		}
		
		AfterSales afterSales = orderService2.selectAfterSalesByCustomerServiceNumber(yeePayBaseRequest.getAfterSn());
		if (afterSales == null) {
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20802), HttpStatus.OK);
		}
		
		if (afterSales.getStatus() == 3) {
			// 当前订单已经成功售后  请不要重复退钱  不给退的
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C21206), HttpStatus.OK);
		}
		
		if (afterSales.getStatus() == 4) {
			// 被拒绝了  不给退钱
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C21207), HttpStatus.OK);
		}
		
		OrderObject orderObject = orderService2.selectOrderObjectByOrderObjectId(afterSales.getOrderObjectId());
		if (orderObject == null) {
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20802), HttpStatus.OK);
		}
		
		// 总金额
		long totel = orderObject.getTotalFee().longValue();
		// 现在退款的金额
		long nowMoney = afterSales.getRefundMoney();
		// 已经成功退款的金额
		long successMoney = afterSalesService.getRefundSuccessMoney(orderObject.getId());

		// 表示全部退款的金额
		if (totel - successMoney <= 0 || nowMoney == 0) {
			afterSales.setRefundId("当前售后订单的实际支付金额为0");
			afterSalesService.userRefundSuccess(afterSales);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C10000), HttpStatus.OK);
		}
		
		// 查询分账信息
		String divideString = orderService2.selectDivideString(afterSales.getOrderDetailId());
		
		if ("FAIL".equals(divideString)) {
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C21211), HttpStatus.OK);
		}
		
		logger.info("------->Divide Args Complete:" + divideString);

		// 构建请求易宝的参数
		List<OrderPay> PayList=
			orderPayMapper.selectPaySuccessByOrderSn(orderObject.getOrderSn(),orderObject.getPayType());
		if(PayList!=null&&PayList.size()>0){
			OrderPay OrderPay=PayList.get(0);
			String appKey = this.baseRestrictionsService.getBaseRestrictionsForCache("app_key").getName();
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("amount", ((afterSales.getRefundMoney().doubleValue()) / 100) + "");
			map.put("orderrequestid", OrderPay.getPaySn());
			map.put("requestid", afterSales.getCustomerServiceNumber());
			map.put("divideinfo", divideString);
			map.put("memo", "售后仅退货款");
			map.put("method", "yeepay.trade.refund");
			map.put("app_key", appKey);
			map.put("format", "json");
			map.put("timestamp", sdf.format(new Date()));
			String requestUrl = baseRestrictionsService.getBaseRestrictionsForCache("yeeRefund_url").getName();
			
			//开始请求
			JSONObject resultJson = JSONObject.parseObject(HttpUtil.post(requestUrl,map));
			String result=JsonUtil.toJson(resultJson);
			
			if (resultJson.getJSONObject("error_response") != null) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000,resultJson.getJSONObject("error_response").getString("msg")), HttpStatus.OK);
			}
			
			if ("1".equals(resultJson.getJSONObject("yeepay_trade_refund_response").getString("code"))) {
				afterSales.setRefundId(resultJson.getJSONObject("yeepay_trade_refund_response").getString("refundexternalid")); // 保存退款流水号
				afterSalesService.userRefundSuccess(afterSales);
				return new ResponseEntity<>(new ResponseResultModel<>(result), HttpStatus.OK);
			} else {
				logger.error("--------->YeePay Refund Faild Response:" + result);
			}
			return new ResponseEntity<>(new ResponseResultModel<>(result), HttpStatus.OK);
		 }
	} catch (Exception e) {
		// TODO: handle exception
		logger.error(e.getMessage(), e);
		return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
	}
	return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C10000), HttpStatus.OK);
//	return false;
	/*

	try {
		OrderObject orderObject = orderService2.selectOrderObjectByOrderObjectId(afterSales.getOrderObjectId());	
						List<OrderPay> PayList=
					orderPayMapper.selectPaySuccessByOrderSn(orderObject.getOrderSn(),orderObject.getPayType());
						OrderInfo info= orderInfoMapper.selectByPrimaryKey(afterSales.getOrderInfoId());
						if(info==null&&info.getId()!=null)
							return false;
						Long orderID=0-info.getId().longValue();
						OrderSettlement settlement = orderSettlementMapper
								.selectByOrderDetailId(orderID);
						String divideString =orderService2.selectFreightDivideString(settlement);
						Integer freight=settlement.getTotalFee();//实付运费
						Integer Coinfreight=settlement.getCashCoin();//妆币运费
						Integer Balancefreight=settlement.getBalancePaid();//余额运费
						if ("FAIL".equals(divideString)) {
							return false;
						}
					if(PayList!=null&&PayList.size()>0){
						OrderPay OrderPay=PayList.get(0);
						// 构建请求易宝的参数
						String freightSn = "F" + OrderUtil.getOrderSn();//请求号
						String appKey = this.baseRestrictionsService.getBaseRestrictionsForCache("app_key").getName();
						Map<String,Object> map = new HashMap<String, Object>();
						map.put("amount", ((freight.doubleValue()) / 100) + "");
						map.put("orderrequestid", OrderPay.getPaySn());
						map.put("requestid",freightSn);
						map.put("divideinfo", divideString);
						map.put("memo", "售后仅退货款(运费款)");
						map.put("method", "yeepay.trade.refund");
						map.put("app_key", appKey);
						map.put("format", "json");
						map.put("timestamp", sdf.format(new Date()));
						String requestUrl = baseRestrictionsService.getBaseRestrictionsForCache("yeeRefund_url").getName();
						JSONObject resultJson = JSONObject.parseObject(HttpUtil.post(requestUrl,map));
						map.put("responseJSON", resultJson.toJSONString());
						if (resultJson.getJSONObject("error_response") != null) {
							logger.error("------>"+resultJson.getJSONObject("error_response"));
							return  false;
						}
						if (resultJson.getJSONObject("yeepay_trade_refund_response")!=null&&
							"1".equals(resultJson.getJSONObject("yeepay_trade_refund_response").getString("code"))) {
							afterSalesMapper.updateAfterSalesByID(afterSales.getId(),map.toString(),
									resultJson.getJSONObject("yeepay_trade_refund_response").getString("refundexternalid"),freight);
 							// 取消已经生成的运费结算信息
 							int updateOrderSettlementStatus = orderSettlementMapper.updateOrderSettlementStatusByOrderDetailId(orderID);
 							if (updateOrderSettlementStatus <= 0) {
 								logger.error("------>取消结算信息失败，订单详情ID："+orderID);
 							}
						} else {
							return  false;
						}				
					}
					if(!refundFreightCommissionAndPoint(afterSales, Coinfreight, Balancefreight)){//退运费失败
						return false;
					}
					} catch (Exception e) {
						return  false;
					}
	return true;
	
*/}
	/**
	 * 分账核对
	 */
	public void fenzhanghedui() {
		YeePayQueryDivideModel model=new YeePayQueryDivideModel();
		model.setOrderrequestid("PAY150778759066857879");
		String result=yeePay.yeePayQueryDivide(model);
		System.out.println(result);
	}
	/**
	 * 可分佣订单进行分佣处理订单
	 */
	public void fenyong() {
		//分佣
		logger.info("--------autoOrderCommision start---------");
			//获取可分佣交易单
			List<OrderObject> orderObjList = orderService2.selectOrderObjectForCommision();
			if (orderObjList == null || orderObjList.size() == 0) {
				return;
			}
			//根据可分佣交易单查找可分佣子订单
			List<OrderInfo> orderInfoList = orderService2.selectOrderInfoInOOIdForCommision(orderObjList);
			Map<Long, OrderInfo> orderInfoIDMap = new HashMap<Long, OrderInfo>();
			Map<String, OrderInfo> orderInfoSNMap = new HashMap<String, OrderInfo>();
			for (OrderInfo orderInfo : orderInfoList) {
				orderInfoIDMap.put(orderInfo.getId(), orderInfo);
				orderInfoSNMap.put(orderInfo.getOrderSn(), orderInfo);
			}
			//以订单为单位处理余额事务和妆币事务
			for(OrderObject OrderObj:orderObjList){
				try {			
					List<OrderObject> orderObjectListTemp= new ArrayList<OrderObject>();
					orderObjectListTemp.add(OrderObj);
					List<UserJournal> userJournalList = new ArrayList<UserJournal>();//佣金流水
					List<UserPointJournal> userPointJournalList = new  ArrayList<UserPointJournal>();//积分流水
					//根据可分佣交易单查找未处理分佣明细
					List<Commision> commisionList = orderService2.selectInOrderObjectIdForCommision(orderObjectListTemp);
					//根据可分佣交易单查找未处理积分明细
					List<CUserPointTransaction> PointTransactionList = 
							orderService2.selectInOrderObjectIdForPoint(orderObjectListTemp);
					//根据余额事务集合生成流水信息
					for (Commision commision : commisionList) {
						if (orderInfoIDMap.get(commision.getOrderInfoId()) == null) {
							logger.error("---orderInfoId---数据异常" + commision.getOrderInfoId());
							continue;
						}
						String KeepAccountsType="";
						//获取佣金的账务类型
						if(orderInfoIDMap.get(commision.getOrderInfoId()).getStoreId().intValue()==StoreTypeEnum.T13.getCode()){
							KeepAccountsType=KeepAccountsTypeConstants.COMMISSION_NOSKIN79;
						}else{
							KeepAccountsType=KeepAccountsTypeConstants.COMMISSION_SKIN79;
						}
						//封装分佣流水
						UserJournal userJournal = new UserJournal();
						userJournal.setUserId(commision.getUserId());
						userJournal.setOrderSn(orderInfoIDMap.get(commision.getOrderInfoId()).getOrderSn());
						userJournal.setPromotionDetailId(orderInfoIDMap.get(commision.getOrderInfoId()).getPromotionId());
						userJournal.setMoney(commision.getFee());
						userJournal.setType(CommonConstants.USER_JOURNAL_TYPE_ADD);
						userJournal.setBankId(0);
						userJournal.setStatus(2);
						userJournal.setComment(commision.getComment());
						userJournal.setBusinessTypeId(commision.getBusinessTypeId());
						userJournal.setBusinessTypeName(commision.getBusinessTypeName()); 
						userJournal.setIsDelete(0);
						userJournal.setCommisionId(commision.getId().intValue());
						userJournal.setKeepAccountsType(KeepAccountsType);
						userJournalList.add(userJournal);
					}
					//根据妆币事务生成妆币流水
					for(CUserPointTransaction pointTransaction:PointTransactionList){
						UserPointJournal pointJournal = new UserPointJournal();
						String KeepAccountsType="";
						//获取佣金的账务类型
						if(orderInfoSNMap.get(pointTransaction.getOrderSn()).getStoreId().intValue()==StoreTypeEnum.T13.getCode()){
							KeepAccountsType=KeepAccountsTypeConstants.POINT_NOSKIN79;
						}else{
							KeepAccountsType=KeepAccountsTypeConstants.POINT_SKIN79;
						}
						pointJournal.setValueByPointTransaction(pointTransaction);// 积分事务到积分记录表
						pointJournal.setBusinessSourceId(pointTransaction.getId());//业务源单ID
						pointJournal.setKeepAccountsType(KeepAccountsType);// 财务记账类型
						userPointJournalList.add(pointJournal);
					}
					orderService2.autoCommision(commisionList,userJournalList,
							PointTransactionList,userPointJournalList, orderObjectListTemp);
					logger.info("--------autoOrderCommision end---------");
				}catch (Exception e) {
							logger.error("--------autoOrderCommision error-------objSN:"+OrderObj.getOrderSn());
							logger.error(e.getMessage(), e);
				  }
			}
}
	/**
	 * 支付成功的易宝订单分账失败的 并进行分账
	 */
	public void fenzhang() {
		try {
			orderService2.divide("P150832654405169339");
		} catch (Exception e) {
			System.out.println(e.getMessage());
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		/*List<String> orderStr=dataCheckMapper.orderSettlementWithNoAccount();
		System.out.println(orderStr.size());
		for(String str:orderStr){
			try {
				System.out.println(str);
				orderService2.divide(str);
			} catch (Exception e) {
				System.out.println(e.getMessage());
				e.printStackTrace();
			}
		}*/
	}
	/**
	 * 支付成功但是 回调失败的订单  包含重复支付的情况
	 */
	public void paySuccessCallError() {/*
		// 查找易宝支付日志数量
		long sizes = xzNotifyLogMapper.selectAllCount();
		long pagenumbers = sizes / 1000;
		int[] paySuccessStatus = {1,5};//支付失败
		try {
			// 每一千条执行一次
			for (int i = 0; i <= pagenumbers; i++) {
					List<XzNotifyLog> listNotifyLog = xzNotifyLogMapper
							.selectByPage(i * 1000, 1000);
				for (XzNotifyLog log : listNotifyLog) {
					String resultJSON = log.getResult();
					if(!StringUtils.contains(resultJSON,"SUCCESS")){//重复推送 推送出现抛异常 的不处理
						continue;
					}
					JSONObject objJson = JSON.parseObject(
							StringUtils.substring(resultJSON,StringUtils.indexOf(resultJSON,"{")));
					if ("1".equals(objJson.getString("code"))) {// 支付成功
						List<OrderPay> orderPay = orderPayMapper
								.selectPaySuccessByPaySn(objJson
										.getString("requestid"));// 获取支付成功的信息
						if (orderPay == null||orderPay.size()==0) {
							System.out.println(objJson.getString("requestid")
									+ " 支付单号未找到支付成功信息 "+objJson.getString("paydate"));
							continue;
						}
						if (orderPay != null && orderPay.size() > 1) {// 重复支付
							System.out.println(objJson.getString("requestid")
									+ " " + orderPay.get(0).getOrderSn()
									+ " 重复支付 "+objJson.getString("paydate"));
							continue;
						}
						OrderObject orderobj = orderObjectMapper
								.selectByOrderSn(orderPay.get(0).getOrderSn());
						if (ArrayUtils.contains(paySuccessStatus, orderobj
								.getStatus().intValue())) {
							System.out.println(objJson.getString("requestid")
									+ " " + orderPay.get(0).getOrderSn()
									+ " 回调支付信息失败 订单状态  "+orderobj.getStatus()+" "+objJson.getString("paydate"));
							continue;
						}
					}
				}
			}
		} catch (Exception e) {
			System.out.println("出错:"+e.getMessage());
		}
	*/}
	private OrderService getOrderService(String orderServiceName) {
		return orderServiceMap.get(orderServiceName);
	}
}